package com.example.ycdyus.dailyfruit.adapter;

import android.content.Context;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.ycdyus.dailyfruit.R;
import com.example.ycdyus.dailyfruit.bean.Main;
import com.example.ycdyus.dailyfruit.utils.ImageLoaderHelper;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.io.DataInputStream;
import java.security.Policy;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by ycdyus on 2015/10/22.
 */
public class GuoyuquanListViewAdapter extends CommonAdapter<Main> {
    private DisplayImageOptions options;
    private Context context;
    private GuoyouGridViewAdapter adapter;
    private List<String> list = new ArrayList<>();
    public GuoyuquanListViewAdapter(Context context, List<Main> mDatas, int itemLayoutId) {
        super(context, mDatas, itemLayoutId);
        options = ImageLoaderHelper.getDisplayImageLoader();
        adapter =  new GuoyouGridViewAdapter(context,list,R.layout.item_only_img);
        this.context = context;
    }

    @Override
    public void convert(ViewHolders holder, Main item) {
        ImageLoader.getInstance().displayImage(item.getData().getUserface(), (ImageView) holder.getView(R.id.iv_item_guoyou_image), options);

        ((TextView)holder.getView(R.id.tv_item_guoyou_name)).setText(item.getData().getUsername());

//        ((ImageView)holder.getView(R.id.tv_item_guoyou_dengji))
        GridView gv =  (GridView)holder.getView(R.id.ll_item_add);
        if(!list.isEmpty()){
            list.clear();
        }
        for (int i = 0; i < item.getData().getPhoto().size(); i++) {
            if(item.getData().getPhoto().get(i)!=null&&!item.getData().getPhoto().get(i).equals("")){
                list.add(item.getData().getPhoto().get(i));
            }
            if(list.isEmpty()||list.size()==0){
                gv.setVisibility(View.GONE);
            }else{
                gv.setVisibility(View.VISIBLE);
            }
        }
        gv.setAdapter(adapter);
        int time = (item.getData().getStime()-Integer.parseInt(item.getData().getCtime()))/60;
        ((TextView) holder.getView(R.id.tv_item_guoyou_time)).setText(time+"分钟前");
        ((TextView)holder.getView(R.id.tv_item_guoyou_content)).setText(item.getData().getTitle());
        ((TextView)holder.getView(R.id.tv_item_guoyou_description)).setText(item.getData().getDescription());
        ((TextView)holder.getView(R.id.tv_item_guoyou_zan)).setText(item.getData().getWorth_num()+"");
        ((TextView)holder.getView(R.id.tv_item_guoyou_pinlun)).setText(item.getData().getComment_num()+"");
    }
}
